<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>style绑定</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<style>
    .static {
        border: 1px solid black;
        width: 100px;
        height: 100px;
    }
</style>

<body>

    <!-- 
     
    -->

    <!-- 准备一个容器 -->
    <div id="app">
        <h1>{{msg}}</h1>

        <!-- 静态写法 -->
        <div class="static" style="background-color: green;">{{msg}}</div> <br />

        <!-- 动态写法：字符串形式 -->
        <div class="static" :style="myStyle">{{msg}}</div> <br />

        <!-- 动态写法：数组形式 -->
        <div class="static" :style="styleArray">{{msg}}</div> <br />

        <!-- 动态写法：对象形式 -->
        <!-- 对象中的属性名要改为驼峰，且属性值为单引号包裹 -->
        <div class="static" :style="{backgroundColor: 'gray'}">{{msg}}</div> <br />
        <div class="static" :style="styleObj">{{msg}}</div> <br />

    </div>

    <script>

        const vm = new Vue({
            el: '#app',
            data: {
                msg: 'style绑定',
                myStyle: 'background-color: gray;',
                styleObj: {
                    backgroundColor: 'yellow'
                },
                styleArray: [
                    { backgroundColor: 'red' },
                    { color: 'blue' }
                ]
            }
        })
    </script>


</body>


</html>